function* foo(val) {
  console.log("1", val);

  const value1 = 100;
  console.log(value1);
  const ret = yield value1;
  console.log(ret);

  const value2 = 200;
  console.log(value2);
  yield value2;

  const value3 = 300;
  console.log(value3);
  yield value3;

  const value4 = 400;
  console.log(value4);
  yield value4;

  console.log("fn run... finish");
  return "finish";
}

const generator = foo(10);

// 终止执行
generator.return();

// 抛出异常, 如果出现了某种情况的话
generator.throw();
